package org.codeanalyzer.model;

public abstract class ApiItem implements Comparable<ApiItem>
{
    protected final String name;

    ApiItem(String name)
    {
        if (name == null)
            throw new IllegalArgumentException("name must not be null.");
        this.name = name;
    }

    public String getName()
    {
        return name;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ApiItem other = (ApiItem)obj;
        if (name == null && other.name != null)
        {
            return false;
        }
        return name.equals(other.name);
    }

    @Override
    public int compareTo(ApiItem o)
    {
        return name.compareTo(o.name);
    }

    @Override
    public String toString()
    {
        return name;
    }
}
